﻿using Newtonsoft.Json;
using System;

namespace Lhz.Serialization
{
    public class JsonSerializer : Serializer<string>
    {
        public override string Serialize<T>(T item)
        {
            return JsonConvert.SerializeObject(item, new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
                PreserveReferencesHandling = PreserveReferencesHandling.Objects
            });
        }

        public override object Deserialize(Type type, string content)
        {
            return JsonConvert.DeserializeObject(content, type);
        }
    }
}
